package com.hcinfos.gsoo.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.hcinfos.gsoo.R;

public class TimeGridViewAdapter extends BaseAdapter {
	private LayoutInflater inflater;
	private List<String> items;
	public int selectPosition = -1;

	public TimeGridViewAdapter(Context context, List<String> items) {
		this.items = items;
		inflater = LayoutInflater.from(context);

	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = this.inflater.inflate(R.layout.time_item, null);
			holder.tv = (TextView) convertView.findViewById(R.id.tv);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}

		holder.tv.setText(items.get(position));
		if (selectPosition == position) {
			holder.tv.setBackgroundColor(Color.parseColor("#00ADEF"));
			holder.tv.setTextColor(Color.WHITE);
		} else {
			holder.tv
					.setBackgroundResource(R.drawable.wb_personal_item_full_normal);
			holder.tv.setTextColor(Color.parseColor("#333333"));
		}
		return convertView;
	}

	public void setDataChange(List<String> times) {

		this.items = times;
		notifyDataSetChanged();
	}

	private class ViewHolder {
		TextView tv;
	}

	public void setPosition(int position) {

		this.selectPosition = position;
		notifyDataSetChanged();
	}

}
